﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<TPOJ.Model.Standing>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Contest Standing
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Contest Standing -- <%= ViewData["contestTitle"] %></h2>
    <table><tbody><tr><td class="solved">Accepted</td><td class="attempted">Rejected</td><td class="pending">Pending</td></tr></tbody></table>
    <br />
    <table>
        <tr>
            <th>
                Rank
            </th>
            <th>
                User
            </th>
            <th>
                Accepts
            </th>
            <th>
                Time
            </th>
     <% for (int i = 0; i < (int)ViewData["length"]; i++)
        {%>
            <th><%= Convert.ToChar('A' + i) %></th>
     <% } %>
        </tr>
        
    <% int j = 0;
       var stub = new TPOJ.Model.StandingCell { Time = 0, Submits = 0, WA_Submits = 0 };
       var cell = stub; %>
    <% foreach (var item in Model)
       { %>
    <% j++; %>
    
        <tr>
            <td>
                <%= j %>
            </td>
            <td>
                <%= Html.Encode(TPOJ.Web.Utils.GetUserName(item.AccountId))%>
            </td>
            <td>
                <%= Html.Encode(item.Accepts) %>
            </td>
            <td>
                <%= Html.Encode(item.Time) %>
            </td>
            <% var standingCells = item.StandingCells.ToDictionary(c => c.Id);
               for (int k = 0; k < (int)ViewData["length"]; k++)
               {
                   if(!standingCells.ContainsKey(k))
                       cell = stub;
                   else
                       cell = standingCells[k];
           %>
            <td class="<%=TPOJ.Web.Utils.StandingCSSClass(cell.Time) %>">
                <%= TPOJ.Web.Utils.FormatStandingCell(cell.Time, cell.Submits, cell.WA_Submits) %>
            </td>
         <% } %>
        </tr>
    
    <% } %>

    </table>
</asp:Content>
